<?php
/**
 * Created by PhpStorm.
 * User: sl
 * Date: 2018/5/24
 * Time: 14:55
 */

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Exception;

class Dict extends Controller
{
    // 角色列表
    public static function getRoleList() {
        $condition[] = ['STATUS','eq','1'];
        $condition[] = ['IS_DEL','eq','0'];
        $res = Db::table('MNG_GZ_ROLE')
            ->where($condition)
            ->select();
        return $res;
    }

    // 隶属单位列表
    public static function getBelongList() {
        $res = Db::table('ASSET_DICT_BELONG')
            ->select();
        return $res;
    }

    /**
     * 学院
     */
    public static function getCollege(){
        $data = Db::table('DICT_COLLEGE')
            ->field('COLLEGE_ID,SHORTNAME')
            ->where(['DEL_MARK'=>'0'])
            ->order('COLLEGE_ID ASC')
            ->select();
        return $data;
    }

    /**
     * 部门
     */
    public static function getDepartment() {
        $collegeId = input('collegeId');
        $condition[] = ['SHOW_MARK', 'eq', '1'];
        if (!empty($collegeId)) {
            $condition[] = ['DEPART_BELONG', '=', $collegeId];
        }

        $res = Db::table('DICT_SB_DEPARTMENT')
            ->field('DEPART_ID,cast(DEPART_SHORT as varchar2(30)) DEPART_SHORT')
            ->where($condition)
            ->order('DEPART_ID ASC')
            ->select();
        return $res;
    }

    /**
     * 国别
     */
    public static function getCountry(){
        return Db::table('DICT_COUNTRY')->field("COUNTRY_ID ID,COUNTRY_CNNAME NAME")->order('COUNTRY_CNNAME ASC')->select();
    }

    /**
     * 家具状态
     */
    public static function getFurnState() {
        $res = Db::table('FURN_DICT_STATE')
            ->select();
        return $res;
    }

    /**
     * 家具分类
     */
    public static function getFurnType(){
        return Db::table('DICT_FURN_FACITYPE')->select();
    }

    /**
     * 家具国有资产分类
     */
    public static function getFurnAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')->field('CCODE94 ID,CNAME94 NAME')->where([['CCODE94','like','90%']])->select();
    }

    /**
     * 家具国标
     */
    public static function getFurnGB(){
        return Db::table('FURN_DICT_GB')->select();
    }

    /**
     * 家具资金来源
     */
    public static function getFurnZJLY(){
        return Db::table('DICT_FURN_ZIJIN')->select();
    }

    /**
     * 家具变动类型
     */
    public static function getFurnAlterType(){
        return Db::table('FURN_DICT_ALTERTYPE')->select();
    }

    /**
     * 无形资产分类
     */
    public static function getIntangibleAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')
            ->where([['CCODE94','like','98%']])
            ->select();
    }

    /**
     * 使用方向
     */
    public static function getUseDirection(){
        return Db::table('ASSET_DICT_USEDIRECTION')->select();
    }

    /**
     * 取得方式
     */
    public static function getGetType(){
        try{
            return Db::table('ASSET_DICT_GETTYPE')->select();
        }
        catch (Exception $e){
            return $e->getMessage();
        }
    }

    /**
     * 资产状态
     */
    public static function getAssetStatus(){
        return Db::table('ASSET_DICT_STATUS')->select();
    }

    /**
     * 采购组织形式
     */
    public static function getPurchase(){
        return Db::table('ASSET_DICT_PURCHASE')->select();
    }

    /**
     * 对外投资性质
     */
    public static function getInvestType(){
        return Db::table('DICT_INVEST_TYPE')->select();
    }

    /**
     * 年份
     */
    public static function getYear(){
        $thisYear = Date('Y');
        $maxYear = $thisYear+2;
        $minYear = $thisYear-20;
        $data = range($maxYear,$minYear);
        return $data;
    }

    /**
     * 资产类型
     */
    public static function getAssetsDictLiquidList() {
        return Db::table('ASSET_DICT_LIQUID')->select();
    }

    /**
     * 图书资产分类
     */
    public static function getBookAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')
            ->where([['CCODE94','like','85%']])
            ->select();
    }

    /**
     * 入账形式
     */
    public static function getEnterType(){
        return Db::table('ASSET_DICT_ENTER_TYPE')->select();
    }


    /**
     * 价值类型
     */
    public static function getValueType(){
        return Db::table('ASSET_DICT_VALUETYPE')->select();
    }

    /**
     * 土地资产分类
     */
    public static function getLandAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')
            ->where([['CCODE94','like','01%']])
            ->select();
    }

    /**
     * 房屋资产分类
     */
    public static function getBuildingAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')
            ->where([['CCODE94','like','02%']])
            ->select();
    }

    /**
     * 产权形式
     */
    public static function getPropertyRight(){
        return Db::table('ASSET_DICT_PROPERTYRIGHT')->select();
    }

    /**
     * 权属性质
     */
    public static function getPowerType(){
        return Db::table('ASSET_DICT_POWERTYPE')->select();
    }

    /**
     * 车辆资产分类
     */
    public static function getCarAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')
            ->where([['CCODE94','like','531%']])
            ->select();
    }

    /**
     * 设备经费科目
     */
    public static function getFinin(){
        return Db::table('DICT_SB_FININ')->select();
    }

    /**
     * 设备分类
     */
    public static function getFacitype(){
        $data = Db::table('DICT_SB_FACITYPE')->select();
        return $data;
    }

    /**
     * 设备开放
     */
    public static function getFaciOpen(){
        return [['ID'=>'0','NAME'=>'不开放'],['ID'=>'1','NAME'=>'开放']];
    }

    /**
     * 设备状态
     */
    public static function getSbState(){
        return Db::table('DICT_SB_STATE')->select();
    }

    /**
     * 设备免税
     */
    public static function getDutyFree(){
        return [['ID'=>'0','NAME'=>'不免税'],['ID'=>'1','NAME'=>'免税']];
    }

    /**
     * 是否审核
     */
    public static function getAudit(){
        return [['ID'=>'0','NAME'=>'未审核'],['ID'=>'1','NAME'=>'已审核']];
    }

    /**
     * 设备变动类型
     */
    public static function getSbAlterType(){
        return Db::table('DICT_SB_ALTERTYPE')->where(['ALTERTYPE_ID'=>['02','05','99']])->select();
    }

    /**
     * 设备变动原因
     */
    public static function getSbAlterCause(){
        return Db::table('DICT_SB_ALTERCAUSE')->select();
    }

    /**
     * 资产分类
     */
    public static function getAssetType(){
        return Db::table('ASSET_DICT_TYPE94TO2010')->select();
    }

    /**
     * 折旧状态
     */
    public static function getDepreciate(){
        return Db::table('ASSET_DICT_DEPRECIATE')->select();
    }

    /**
     * 建筑结构
     */
    public static function getConstru(){
        return Db::table('ASSET_DICT_CONSTRU')->select();
    }

    /**
     * 审批情况
     */
    public static function getInvestAuditStatusList() {
        return Db::table('DICT_INVEST_AUDIT_STATUS')->select();
    }

    /**
     * 是否
     */
    public static function getIsOrNot() {
        return [['ID'=>'0','NAME'=>'不是'],['ID'=>'1','NAME'=>'是']];
    }

    /**
     * 编制情况
     */
    public static function getCompile() {
        return Db::table('ASSET_DICT_COMPILE')->select();
    }

    /**
     * 土地变动类别
     */
    public static function getLandAlterType() {
        return Db::table('ASSET_DICT_ALTERTYPE')->select();
    }

    /**
     * 构筑物变动类别
     */
    public static function getBuildingAlterType() {
        return Db::table('ASSET_DICT_ALTERTYPE')->where([['ALTERTYPE_ID','in','51,52,53,54,55,56,57']])->select();
    }

    /**
     * 库存分类列表
     */
    public static function getStockType() {
        return Db::table('DICT_STOCK_TYPE')->select();
    }

    /**
     * 库存取得方式
     */
    public static function getGetStockType() {
        return Db::table('DICT_STOCK_GET_TYPE')->select();
    }

    /**
     * 在建工程投入使用状况
     */
    public static function getConsUseState() {
        return Db::table('DICT_CONS_USE_STATE')->select();
    }

    /**
     * 在建工程项目性质
     */
    public static function getConsNature() {
        return Db::table('DICT_CONS_NATURE')->select();
    }

    /**
     * 在建工程项目类型
     */
    public static function getConsType() {
        return Db::table('DICT_CONS_TYPE')->select();
    }

    /**
     * 所属在建工程
     */
    public static function getConstruction() {
        $data = Db::table('CONSTRUCTION_INFO')
            ->field('CONS_ID,concat(CONS_NO,CONS_NAME) CONS_BELONG')
            ->select();
        return $data;
    }

    /**
     * 是否
     */
    public static function getIsNot() {
        return [['ID'=>'0','NAME'=>'否'],['ID'=>'1','NAME'=>'是']];
    }
}